package com.example.cinema.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.example.cinema.BR;
import com.example.cinema.bindingdata.VideoData;

import java.util.List;

public class TypeGridAdapter<T> extends BaseAdapter {

    private Context context;
    private List<T> data;
    private int layoutid;
    private LayoutInflater inflater;
    public TypeGridAdapter(Context context, List<T> data,int layoutid) {
        this.context = context;
        this.data = data;
        this.inflater = LayoutInflater.from(context);
        this.layoutid = layoutid;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }



    private ViewDataBinding dataBinding;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            dataBinding = DataBindingUtil.inflate(inflater,layoutid,parent,false);
            convertView = dataBinding.getRoot();
        }
        dataBinding.setVariable(BR.vdatas,data.get(position));
        return convertView;
    }
}
